package com.qyhl.module_practice.score.mine.act;


import com.qyhl.module_practice.common.PracticeUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.entity.civilized.PracticeAcitivityBean;

import java.util.List;

public class PracticeScoreMyActivityModel implements PracticeScoreMyActivityContract.PracticeScoreMyActivityModel {
    private PracticeScoreMyActivityPresenter mPresenter;

    PracticeScoreMyActivityModel(PracticeScoreMyActivityPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }


    @Override
    public void getList(String volId, final String page) {

        EasyHttp.get(PracticeUrl.GET_PRACTICE_SCORE_MY_ACT)
                .params("volId", volId)
                .params("page", page)
                .execute(new SimpleCallBack<List<PracticeAcitivityBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        } else {
                            mPresenter.setError("请求出错，请重新获取！", !page.equals("1"));
                        }
                    }

                    @Override
                    public void onSuccess(List<PracticeAcitivityBean> practiceAcitivityBeans) {
                        if (practiceAcitivityBeans != null && practiceAcitivityBeans.size() > 0) {
                            mPresenter.setList(practiceAcitivityBeans, !page.equals("1"));
                        } else {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        }
                    }
                });
        
    }

    @Override
    public void getPublicList(String phone, String page) {
        EasyHttp.get(PracticeUrl.GET_PRACTICE_SCORE_PUBLIC_ACT)
                .params("phone", phone)
                .params("page", page)
                .execute(new SimpleCallBack<List<PracticeAcitivityBean>>() {

                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        } else {
                            mPresenter.setError("请求出错，请重新获取！", !page.equals("1"));
                        }
                    }

                    @Override
                    public void onSuccess(List<PracticeAcitivityBean> practiceAcitivityBeans) {
                        if (practiceAcitivityBeans != null && practiceAcitivityBeans.size() > 0) {
                            mPresenter.setList(practiceAcitivityBeans, !page.equals("1"));
                        } else {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        }
                    }
                });
    }
}
